package cn.cs.yangtai.service.impl;

import cn.cs.yangtai.entity.Blog;
import cn.cs.yangtai.entity.Shopping;
import cn.cs.yangtai.entity.vo.PageResult;
import cn.cs.yangtai.entity.vo.ShoppingVo;
import cn.cs.yangtai.mapper.ShoppingMapper;
import cn.cs.yangtai.service.ShoppingService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;

/**
 * (Shopping)表服务实现类
 *
 * @author makejava
 * @since 2024-12-12 09:04:27
 */
@Service("shoppingService")
public class ShoppingServiceImpl implements ShoppingService {
    @Resource
    private ShoppingMapper shoppingMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param sId 主键
     * @return 实例对象
     */
    @Override
    public ShoppingVo queryById(Integer sId) {
        return this.shoppingMapper.queryById(sId);
    }

    /**
     * 通过用户ID查询用户购物数据
     *
     * @return 实例对象
     */
    @Override
    public List<ShoppingVo> queryBysUserid(Integer sUserid) {
        return shoppingMapper.queryBysUserid(sUserid);
    }

    /**
     * 分页查询
     *
     * @param cuttentPage 本页
     * @param pageSize    分页大小
     * @return 查询结果
     */
    @Override
    public PageResult<ShoppingVo> queryByPage(Integer cuttentPage, Integer pageSize) {
        PageHelper.startPage(cuttentPage,pageSize);
        Page<ShoppingVo> shoppings =shoppingMapper.queryAllByLimit(new Page<>());
        return PageResult.restPage(shoppings);
    }

    /**
     * 新增数据
     *
     * @param shopping 实例对象
     * @return 实例对象
     */
    @Override
    public Shopping insert(Shopping shopping) {
        this.shoppingMapper.insert(shopping);
        return shopping;
    }

    /**
     * 修改数据
     *
     * @param shopping 实例对象
     * @return 实例对象
     */
    @Override
    public ShoppingVo update(Shopping shopping) {
        this.shoppingMapper.update(shopping);
        return this.queryById(shopping.getSId());
    }

    /**
     * 通过主键删除数据
     *
     * @param sId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer sId) {
        return this.shoppingMapper.deleteById(sId) > 0;
    }
}
